/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * Projects
 * Copyright (C) Arnaud Duval 2010 <arnaud.duval@gmail.com>
 * 
 * Projects is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Projects is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "integer-entry.hpp"
#include <sstream>


//Default constructor
IntegerEntry::IntegerEntry() : Gtk::Entry()
{
	value = 0;
    displayIfZero = true;
	set_text("0");
}

//Destructor
IntegerEntry::~IntegerEntry()
{
	
}

///@brief Set the value
///@param val New value
void IntegerEntry::SetValue(int val)
{
	value = val;
	std::ostringstream stream;
	stream << val;
	set_text(stream.str());
}

///@brief Get the value
int IntegerEntry::GetValue()
{
	return value;
}

///@brief Update the value when the content of the entry is changed
void IntegerEntry::on_changed()
{
	std::istringstream stream(get_text());
	stream >> value;
    if((!displayIfZero)&&(value == 0))
    {
        set_text("");
    }
}

///@brief Set the entry to display the value if it is equal to zero
void IntegerEntry::DisplayIfZero()
{
    displayIfZero = true;
    on_changed();
}

///@brief Set the entry to not display the value if it is equal to zero
void IntegerEntry::NotDisplayIfZero()
{
    displayIfZero = false;
    on_changed();
}
         